<div id="<?php echo $id;?>" class='etreeselect-results input'>
	<a href='#TB_inline?&inlineId=hidden_<?php echo $id;?>' class='thickbox' title='<?php echo $options['title']; ?>'><?php echo $options['text']; ?></a>
	<?php 
	if($model->{$name}){
		foreach($model->{$name} as $data_id=>$data_text){
			echo '<span class="'.$data_id.'">'.$data_text.'<input type="hidden" value="'.$data_text.'" name="'.get_class($model).'['.$name.']['.$data_id.']"></span>';
		}
	}
	?>
</div>

<div id='hidden_<?php echo $id;?>' style='display:none' class='<?php echo $options['multiple']?'multiple':''; ?>'> 
	<div class='ETreeSelect'>
		<div id='result_<?php echo $id; ?>' class='norm-font border-bottom etreeselect-thickbox-result'>
		<?php 
		if($model->{$name}){
			foreach($model->{$name} as $data_id=>$data_text){
				echo '<a href="#" title="РЈРґР°Р»РёС‚СЊ СЂР°Р·РґРµР» '.$data_text.'" class="part-selector" rel="'.$data_id.'">'.$data_text.'</a>';
			}
		}
		?>
		</div>
		<div id='sidetreecontrol_<?php echo $id; ?>' class='norm-font' ><a href="#">РЎРІРµСЂРЅСѓС‚СЊ РІСЃРµ</a> | <a href="#">Р Р°Р·РІРµСЂРЅСѓС‚СЊ РІСЃРµ</a></div>
		<?php
			$this->widget('CTreeView', array(
				'id'=>'ETreeSelect_'.$id,
				'data'=>$tree,
				'collapsed'=>true,
				'control'=>'#sidetreecontrol_'.$id,
				#'unique'=>true,
				'animated'=>'fast'
			));
		?>
	</div>
</div> 

<script type='text/javascript'>
jQuery(document).ready(function() {
	$('#hidden_<?php echo $id;?> .part-selector').click(function(){
		var parent = $(this).parents('div.ETreeSelect');
		
		if( $(parent).find('.etreeselect-thickbox-result a[rel='+$(this).attr('rel')+']').length <= 0){
			if(!$('#hidden_<?php echo $id;?>').hasClass('multiple')){
				$(parent).find('.etreeselect-thickbox-result a').remove();
				$('#<?php echo $id;?>').find('span').remove();
			}
			
			$(parent).find('.etreeselect-thickbox-result').append(
				$(this).clone().attr({
					'title': 'РЈРґР°Р»РёС‚СЊ СЂР°Р·РґРµР» '+$(this).html(),
					'class': 'part-selector'
				})
			);
			
			$('#<?php echo $id;?>').append(
				'<span class="'+$(this).attr('rel')+'">'+$(this).html()+'<input type="hidden" name="<?php echo get_class($this->model).'['.$this->name.']'; ?>['+$(this).attr('rel')+']" value="'+$(this).html()+'" /></span>'
			);
		}
	})
	
	$('#result_<?php echo $id;?>.etreeselect-thickbox-result a').live('click',function(){
		$('#<?php echo $id;?>.etreeselect-results').find('span[class='+$(this).attr('rel')+']').remove();
		$(this).remove();
	})
});
</script>